var router = require('express').Router()

var request = require('../request')
var qs = require('qs')

/* 获取文章列表 */
router.get('/articles', function (req, res, next) {
  const params = {};
  
    const {current, classification, keyword} = req.query;
    if(current) {
      params.current = current;
    }
    if(classification) {
      params.classification = classification;
    }
    if(keyword) {
      params.keyword = keyword
    }
    request.get('/anon/articles/read/page', {
      params:{...params, timestamp:new Date().getTime()}
    }).then(function({ data }) {
      res.json(data)
    });
})

/* 获取文章详情 */
router.get('/articles/:id', function (req, res, next) {
  request.get('anon/articles/read/detail', {
    params:{id:req.params.id, timestamp:new Date().getTime()}
  }).then(function( { data }) {
    res.json(data)
  });
})

export default router;
